package com.ttl.config.exception;

import cn.hutool.log.Log;
import cn.hutool.log.LogFactory;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ttl.web.utils.ResultVo;


@ControllerAdvice(basePackages = "com.ttl.web.controller")
public class GlobalExceptionHandler {

    private static final Log log = LogFactory.get();


    //统一异常处理@ExceptionHandler,主要用于Exception
    @ExceptionHandler(Exception.class)
    @ResponseBody//返回json
    public ResultVo error(HttpServletRequest request, Exception e) {
        log.error("异常信息：", e);
        return ResultVo.error();
    }

    @ExceptionHandler(CustomException.class)
    @ResponseBody//返回json
    public ResultVo customError(HttpServletRequest request, CustomException e) {
        return ResultVo.error(e.getMsg());
    }

}
